package com.hu.controller;


import com.hu.config.permission.Role;
import com.hu.config.permission.Roles;
import com.hu.dal.mapper.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.*;

/**
 * 测试Controller
 *
 * @RestController 实现Rest服务的常用注解，相当于在@Controller的基础上，自动为将所有的请求方法追加@ResponseBody
 * 实现以
 */
@Controller
@RequestMapping("/hi")
public class HelloController {
    //1.这里是通过属性依赖注入
    private final UserDao userDao;

    //2.当然还可以通过构造函数注入，先声明属性，然后注入
    @Autowired
    public HelloController(UserDao userDao) {
        this.userDao = userDao;
    }

//    @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象，并根据传过来的user信息来更新用户详细信息")
//    @ApiImplicitParams({@ApiImplicitParam(name = "id", value = "用户ID,long类型"), @ApiImplicitParam(name = "user", value = "用户详细实体user")})


    @RequestMapping(value = "/helloWord", method = RequestMethod.POST)
    @ResponseBody
    @Roles(type =Role.ADMIN)//该注解用于权限管理
    public String testHello() {
        return "helloWord";
    }


    /**
     * 使用模板引擎,返回页面
     * return模板文件的名称，对应src/main/resources/templates/index.html
     */
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(ModelMap model) throws FileNotFoundException {
        File f = new File("aa");
        InputStream ips = new FileInputStream(f);
        userDao.insert("sasasasko");
        model.addAttribute("name", "一号管理员"); // 加入一个属性，用来在模板中读取
        return "user/index";
    }
}